package net.adetech.crj.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.Controller;
import net.adetech.crj.dao.DataDictionary;

import java.util.List;

public class DDController  extends Controller {
    public void ddList(){
        String ddNo = getPara("no");
        renderJson(DataDictionary.getDDList(ddNo));
    }

    public void normalDDList(){
        String ddNo = getPara("no");
        String[] ddNoArray = ddNo.split(",");
        JSONObject result = new JSONObject();

        for (String no:ddNoArray
             ) {
            List<DataDictionary> ddList = DataDictionary.getDDList(no);
            if (ddList!=null&&ddList.size()>0)
            {
                String arrayName = ddList.get(0).getStr("DD_NAME").toLowerCase();
                JSONArray valueArray = new JSONArray();
                JSONArray objectArray = new JSONArray();
                for (DataDictionary dd:ddList
                        ) {
                    String key = dd.getStr("DD_KEY");
                    String value = dd.getStr("DD_VALUE");
                    JSONObject object = new JSONObject();
                    object.put("key",key);
                    object.put("value",value);
                    valueArray.add(value);
                    objectArray.add(object);
                }
                result.put(arrayName+"Array",valueArray);
                result.put(arrayName+"ObjectArray",objectArray);
            }
        }

        renderJson(result.toJSONString());
    }
}
